package com.clh.service.impl;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

import com.clh.common.PageInfo;
import com.clh.dao.ComplaintDao;
import com.clh.dao.impl.ComplaintDaoImpl;
import com.clh.entity.Complaint;
import com.clh.entity.Owner;
import com.clh.service.ComplaintService;

/**
 * 
 * @Description: 投诉界面Service方法体
 * @author 陈志艺
 * @date 2022年5月26日 下午3:33:17
 * @version v1.0
 */
public class ComplaintServiceImpl implements ComplaintService {
	private ComplaintDao comDao = new ComplaintDaoImpl();

	@Override
	public PageInfo<Complaint> getComplaintListByCondtion(String start, String end, String comStatus, String roomNo,
			int pageNum, int pageSize) {
		if (roomNo != null && !"".equals(roomNo)) {
			roomNo = new StringBuffer().append(roomNo).toString();
		}
		// 调用订单表的持久层-多条件分页查询
		List<Complaint> list = comDao.findByPage(start, end, comStatus, roomNo, pageNum, pageSize);
		// 调用订单表的持久层-多条件查询总记录数
		Integer total = comDao.countByCondition(start, end, comStatus, roomNo);
		// 封装分页对象
		PageInfo<Complaint> pageInfo = new PageInfo<Complaint>(list, pageNum, pageSize, total);
		return pageInfo;
	}

	@Override
	public int removeComplaint(String comNo) {
		return comDao.deleteByNo(comNo);
	}

	@Override
	public boolean addComplaint(Complaint com) {
		// 设置商品编号UUID
		UUID uuid = UUID.randomUUID();
		String comNo = uuid.toString().replace("-", "");
		com.setComNo(comNo);
		// 2、设置商品创建时间
		LocalDateTime ldt = LocalDateTime.now();
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		String now = ldt.format(formatter);
		com.setComTime(now);
		// 调用持久层执行插入操作
		return comDao.insert(com) > 0;
	}

	@Override
	public boolean modifyComplaint(Complaint com) {
		return comDao.update(com) > 0;
	}

	@Override
	public Complaint getComById(String comNo) {
		System.out.println("service层"+comNo);
		return comDao.findByNo(comNo);
	}

	@Override
	public List<Owner> countForComplaint(int pageNum,int pageSize) {
		return comDao.countForComplaint(pageNum,pageSize);
	}

}
